package com.swiftride.controller.app;

import cn.dev33.satoken.annotation.SaIgnore;
import com.swiftride.pojo.dto.DriverLocation2GeoDto;
import com.swiftride.result.R;
import com.swiftride.service.IDriverService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;


@Tag(name = "小程序司机", description = "小程序司机接口")
@RestController
@RequestMapping("/app/driver")
public class AppDriverController {

    @Autowired
    private IDriverService driverService;

    @Operation(summary = "司机注册", description = "司机注册接口")
    @Parameter(name = "openidCode", description = "获取openid的code", required = true)
    @GetMapping(value = "/register/{openidCode}")
    @SaIgnore
    public R register(@PathVariable("openidCode") @NotNull(message = "数据不能为空") String openidCode) {
        driverService.register(openidCode, null);
        return R.success();
    }

    @Operation(summary = "司机手机号注册", description = "司机手机号注册接口")
    @Parameter(name = "openidCode", description = "获取openid的code", required = true)
    @GetMapping(value = "/registerByPhone/{openidCode}/{phoneCode}")
    @SaIgnore
    public R registerByPhone(@PathVariable("openidCode") @NotNull(message = "数据不能为空") String openidCode,
                             @PathVariable("phoneCode") String phoneCode) {
        driverService.register(openidCode, phoneCode);
        return R.success();
    }

    @Operation(summary = "司机开始接单", description = "司机开始接单接口")
    @GetMapping("/online")
    public R driverOnline() {
        driverService.driverOnline();
        return R.success();
    }

    @Operation(summary = "司机结束接单", description = "司机结束接单接口")
    @GetMapping("/offline")
    public R driverOffline() {
        driverService.driverOffline();
        return R.success();
    }

    @Operation(summary = "更新司机位置信息到GRO", description = "更新司机位置信息到GRO接口")
    @Parameter(name = "driverSummaryTodayDto", description = "司机位置")
    @PostMapping("/uploadDriverLocation2Geo")
    @SaIgnore
    public R driverLocation2Geo(@RequestBody @NotEmpty DriverLocation2GeoDto driverLocation2GeoDto) {
        driverService.driverLocation2Geo(driverLocation2GeoDto);
        return R.success();
    }
}
